package com.bdqn.desiremall.command;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.bdqn.desiremall.entity.Mall_Goods;
import com.bdqn.desiremall.serivce.goods.GoodsSerivce;
import com.bdqn.desiremall.serivce.goods.GoodsSerivceImpl;
import com.mvc.command.ICommand;

public class ProductCommand implements ICommand {
	GoodsSerivce goodsService = new GoodsSerivceImpl();	
	/**
	 * 查看所有商品
	 * @param request
	 * @param response
	 */
	public void productList(HttpServletRequest request,HttpServletResponse response){
	    Mall_Goods goods = new Mall_Goods();
	    String goodsName = request.getParameter("goods")==""?null:request.getParameter("goods");
	    goods.setGoodsName(goodsName);
	    HttpSession session = request.getSession();
		List<Mall_Goods> goodsView = goodsService.goodsView(goods);
		session.setAttribute("productList", goodsView);
		
       
		
	}
	
	/**
	 * 商品下架
	 */
	public void sold(HttpServletRequest request,HttpServletResponse response){
		Mall_Goods goods = new Mall_Goods();
		int goodsId =Integer.parseInt(request.getParameter("goodsId"));
		System.out.println(goodsId);
		goods.setGoodsId(goodsId);
		//2下架
		goods.setStateId(2);
		goodsService.modifyGoods(goods);
	}
	/**
	 * 商品上架
	 */
	public void shelf(HttpServletRequest request,HttpServletResponse response){
		Mall_Goods goods = new Mall_Goods();
		int goodsId =Integer.parseInt(request.getParameter("goodsId"));
		System.out.println(goodsId);
		goods.setGoodsId(goodsId);
		//2下架
		goods.setStateId(1);
		goodsService.modifyGoods(goods);
	
	}
	
	public void productById(HttpServletRequest request,HttpServletResponse response){
		
		 Mall_Goods goods = new Mall_Goods();	
		    HttpSession session = request.getSession();
			int goodsId =Integer.parseInt(request.getParameter("goodsId"));
		
			System.err.println(goodsId);
			goods.setGoodsId(goodsId);
			
			List<Mall_Goods> goodsView = goodsService.goodsView(goods);
			session.setAttribute("productById", goodsView);
	}
	}
